home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / c / EasygadgetsSou.lha / EasyGadgets / Help.c < prev    next >
C/C++ Source or Header  |  1995-11-10  |  5KB  |  192 lines

  1. /*
  2.  *    File:                    Help.c
  3.  *    Description:    
  4.  *
  5.  *    (C) 1994,1995 Ketil Hunn
  6.  *
  7.  */
  8.  
  9. #ifndef    HELP_C
  10. #define    HELP_C
  11.  
  12. /*** DEFINES *************************************************************************/
  13. #define AMIGAGUIDEVERSION    34L
  14.  
  15.  
  16. /*** FUNCTIONS ***********************************************************************/
  17. __asm UBYTE *egGetHelpNode(    register __a0 struct egTask                *task,
  18.                                                         register __a1 struct IntuiMessage *msg)
  19. {
  20.     register struct egGadget    *gad=task->eglist;
  21.     register WORD                            x=msg->MouseX, y=msg->MouseY;
  22.     UBYTE                                            *node=NULL, *oldnode;
  23.  
  24. #ifdef MYDEBUG_H
  25.     DebugOut("egGetHelpNode");
  26. #endif
  27.  
  28.     while(gad)
  29.     {
  30.         if(    (x>=gad->ng.ng_LeftEdge)    &&     (x<=(gad->ng.ng_LeftEdge+gad->ng.ng_Width)) &&
  31.                 (y>=gad->ng.ng_TopEdge)        &&    (y<=(gad->ng.ng_TopEdge+gad->ng.ng_Height)))
  32.         {
  33.             node=gad->helpnode;
  34.             break;
  35.         }
  36.         gad=gad->NextGadget;
  37.     }
  38.  
  39.     /* Pointer not over a gadget.  Check if over a gadget title */
  40.     if(node==NULL | (gad && gad->kind==EG_GROUP_KIND))
  41.     {
  42.         register UWORD tmp;
  43.  
  44.         oldnode=node;
  45.         node=NULL;
  46.  
  47.         gad=task->eglist;
  48.         while(gad)
  49.         {
  50.             if(gad->ng.ng_GadgetText && gad->helpnode)
  51.                 if(    ISBITSET(gad->ng.ng_Flags, PLACETEXT_LEFT) &&
  52.                         x<=gad->ng.ng_LeftEdge &&
  53.                         x>=gad->ng.ng_LeftEdge-egTextWidth(task->eg, gad->ng.ng_GadgetText)+EG_LabelSpace &&
  54.                         y>=gad->ng.ng_TopEdge &&
  55.                         y<=gad->ng.ng_TopEdge+gad->ng.ng_Height)
  56.                 {
  57.                     node=gad->helpnode;
  58.                     break;
  59.                 }
  60.                 else if(ISBITSET(gad->ng.ng_Flags, PLACETEXT_RIGHT) &&
  61.                         x>(tmp=gad->ng.ng_LeftEdge+gad->ng.ng_Width) &&
  62.                         x<=tmp+egTextWidth(task->eg, gad->ng.ng_GadgetText)+EG_LabelSpace  &&
  63.                         y>=gad->ng.ng_TopEdge &&
  64.                         y<=gad->ng.ng_TopEdge+gad->ng.ng_Height)
  65.                 {
  66.                     node=gad->helpnode;
  67.                     break;
  68.                 }
  69.                 else if(ISBITSET(gad->ng.ng_Flags, PLACETEXT_ABOVE) &&
  70.                         x<gad->ng.ng_TopEdge                                                                &&
  71.                         x>=gad->ng.ng_TopEdge-gad->ng.ng_TextAttr->ta_YSize    &&
  72.                         y>=gad->ng.ng_LeftEdge                                                            &&
  73.                         y<=gad->ng.ng_LeftEdge+gad->ng.ng_Height+EG_LabelSpaceV)
  74.                 {
  75.                     node=gad->helpnode;
  76.                     break;
  77.                 }
  78.                 else if(ISBITSET(gad->ng.ng_Flags, PLACETEXT_BELOW) &&
  79.                         x>(tmp=gad->ng.ng_TopEdge+gad->ng.ng_Height)        &&
  80.                         x<=tmp+gad->ng.ng_TextAttr->ta_YSize                        &&
  81.                         y>=gad->ng.ng_LeftEdge                                                    &&
  82.                         y<=gad->ng.ng_LeftEdge+gad->ng.ng_Height+EG_LabelSpaceV)
  83.                 {
  84.                     node=gad->helpnode;
  85.                     break;
  86.                 }
  87.             gad=gad->NextGadget;
  88.         }
  89.         if(node==NULL)
  90.             node=oldnode;
  91.     }
  92.     return (node==NULL ? task->helpnode:node);
  93. }
  94.  
  95. __asm __saveds BYTE egShowAmigaGuide(    register __a0 struct EasyGadgets    *eg,
  96.                                                                             register __a1 char                                *node)
  97. {
  98.     BYTE success=FALSE;
  99. #ifdef MYDEBUG_H
  100.     DebugOut("egShowAmigaGuide");
  101. #endif
  102.  
  103.     if(AmigaGuideBase==NULL)
  104.         AmigaGuideBase=OpenLibrary("amigaguide.library", AMIGAGUIDEVERSION);
  105.  
  106.     if(AmigaGuideBase)
  107.     {
  108.         sprintf(eg->GuideMsg, "LINK %s", (char *)(node==NULL ? "Main":node));
  109.  
  110.         if(eg->AG_Context==NULL)
  111.         {
  112.             eg->AG_NewGuide.nag_Lock            =NULL;
  113.             eg->AG_NewGuide.nag_Name            =eg->helpdoc;
  114.             eg->AG_NewGuide.nag_Screen        =eg->screen;
  115.             eg->AG_NewGuide.nag_ClientPort=eg->basename;
  116.             eg->AG_NewGuide.nag_BaseName    =eg->basename;
  117.             eg->AG_NewGuide.nag_Flags            =HTF_CACHE_NODE|HTF_NOACTIVATE;
  118.  
  119.             if(eg->AG_Context=OpenAmigaGuideAsync(&eg->AG_NewGuide, TAG_DONE))
  120.             {
  121.                 eg->AmigaGuideSignal=AmigaGuideSignal(eg->AG_Context);
  122.                 success=TRUE;
  123.             }
  124.         }
  125.         else
  126.         {
  127.             SendAmigaGuideCmd(eg->AG_Context, eg->GuideMsg, NULL);
  128.             success=TRUE;
  129.         }
  130.     }
  131.     return success;
  132. }
  133.  
  134. __asm __saveds void egHandleAmigaGuide(register __a0 struct EasyGadgets *eg)
  135. {
  136.     register struct AmigaGuideMsg *agm;
  137.  
  138. #ifdef MYDEBUG_H
  139.     DebugOut("egHandleAmigaGuide");
  140. #endif
  141.  
  142.     if(AmigaGuideBase && eg->AG_Context)
  143.         while(agm=GetAmigaGuideMsg(eg->AG_Context))
  144.         {
  145.             switch(agm->agm_Type)
  146.             {
  147.                 case ActiveToolID:
  148.                     SendAmigaGuideCmd(eg->AG_Context, eg->GuideMsg, NULL);
  149.                     break;
  150.                 case ToolCmdReplyID:
  151.                 case ToolStatusID:
  152.                 case ShutdownMsgID:
  153.                     if(agm->agm_Pri_Ret)
  154.                     {
  155.                         register struct egTask    *task;
  156.  
  157.                         for(task=eg->tasklist; task; task=task->nexttask)
  158.                             if(task->window)
  159.                             {
  160.                                 APTR parms[3];
  161.  
  162.                                 parms[0]=(APTR)GetAmigaGuideString(agm->agm_Sec_Ret);
  163.                                 parms[1]=(APTR)eg->helpdoc;
  164.                                 parms[2]=NULL;
  165.                                 egLockAllTasks(eg);
  166.                                 egRequestA(task->window, task->window->Title, "%s:\n%s", "OK", parms);
  167.                                 egUnlockAllTasks(eg);
  168.                                 break;
  169.                             }
  170.                     }
  171.                     break;
  172.                 }
  173.             ReplyAmigaGuideMsg(agm);
  174.         }
  175. }
  176.  
  177. __asm __saveds void egCloseAmigaGuide(register __a0 struct EasyGadgets *eg)
  178. {
  179. #ifdef MYDEBUG_H
  180.     DebugOut("egCloseAmigaGuide");
  181. #endif
  182.     if(eg->AG_Context)
  183.         CloseAmigaGuide(eg->AG_Context);
  184.     if(AmigaGuideBase)
  185.         CloseLibrary(AmigaGuideBase);
  186.  
  187.     eg->AG_Context=NULL;
  188.     AmigaGuideBase=NULL;
  189. }
  190.  
  191. #endif
  192.